﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace ADO.net_DictionarySoft
{
    public partial class form_MANHINHCHINH : Form
    {
        public form_MANHINHCHINH()
        {
            InitializeComponent();
        }
        public void connectDataBase()
        {
           
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        private void form_MANHINHCHINH_FormClosing(object sender, EventArgs e)
        {
            Application.Exit();
        }
        CSDLConnection csdl = new CSDLConnection();
            
        private void form_MANHINHCHINH_Load(object sender, EventArgs e)
        {
            
            button_DANGXUAT.Hide();
            label_TENTAIKHOAN.Hide();
            button_SUATU.Hide();
            button_SUATUDIEN.Hide();
            button_TAOTUDIEN.Hide();
            button_THEMTU.Hide();
            button_XOATU.Hide();
            button_XOATUDIEN.Hide();
            label_TENTAIKHOAN.Top = label_NGUOIDUNG.Top;
            label_TENTAIKHOAN.Left = button_DANGNHAP.Left;
            button_DANGXUAT.Top = button_DANGKY.Top;
            button_DANGXUAT.Left = button_DANGNHAP.Left + 50;
            

            // lay danh sach tu trong bang Tu
            string ReadDatabase = "select *from Tu";
            csdl.CreateConnect();
            OleDbCommand Command = new OleDbCommand(ReadDatabase, csdl.connectSYSTEM);
            OleDbDataReader ReadCommand;
            
            ReadCommand = Command.ExecuteReader();

            while(ReadCommand.Read())
            {
                string str = "";
                str = str + ReadCommand.GetString(0);
                listbox_DANHSACHTU.Items.Add(str);
            }

            // lay danh sach tu dien trong bang TuDien

            ReadDatabase = "select *from TuDien";
            Command = new OleDbCommand(ReadDatabase, csdl.connectSYSTEM);

            ReadCommand = Command.ExecuteReader();

            while (ReadCommand.Read())
            {
                string str = "";
                str = str + ReadCommand.GetString(1);
                combobox_TENTUDIEN.Items.Add(str);
            }

            combobox_TENTUDIEN.SelectedIndex = 0;
            combobox_TENTUDIEN.Text = combobox_TENTUDIEN.SelectedItem.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void picturebox_Click(object sender, EventArgs e)
        {

        }

        private void button_DANGNHAP_Click(object sender, EventArgs e)
        {

            button_DANGXUAT.Show();
            label_TENTAIKHOAN.Show();
            label_NGUOIDUNG.Hide();
            label_MATKHAU.Hide();
            textbox_MATKHAU.Hide();
            textbox_NGUOIDUNG.Hide();
            button_DANGKY.Hide();
            button_DANGNHAP.Hide();
            button_SUATU.Show();
            button_SUATUDIEN.Show();
            button_TAOTUDIEN.Show();
            button_THEMTU.Show();
            button_XOATU.Show();
            button_XOATUDIEN.Show();
            picturebox.Hide();
        }

        private void button_DANGXUAT_Click(object sender, EventArgs e)
        {
            button_DANGXUAT.Hide();
            label_TENTAIKHOAN.Hide();
            label_NGUOIDUNG.Show();
            label_MATKHAU.Show();
            textbox_MATKHAU.Show();
            textbox_NGUOIDUNG.Show();
            button_DANGKY.Show();
            button_DANGNHAP.Show();
            button_SUATU.Hide();
            button_SUATUDIEN.Hide();
            button_TAOTUDIEN.Hide();
            button_THEMTU.Hide();
            button_XOATU.Hide();
            button_XOATUDIEN.Hide();
            picturebox.Show();
        }

        private void button_DANGKY_Click(object sender, EventArgs e)
        {
            button_DANGXUAT.Show();
            label_TENTAIKHOAN.Show();
            label_NGUOIDUNG.Hide();
            label_MATKHAU.Hide();
            textbox_MATKHAU.Hide();
            textbox_NGUOIDUNG.Hide();
            button_DANGKY.Hide();
            button_DANGNHAP.Hide();
            button_SUATU.Show();
            button_SUATUDIEN.Show();
            button_TAOTUDIEN.Show();
            button_THEMTU.Show();
            button_XOATU.Show();
            button_XOATUDIEN.Show();
            picturebox.Hide();
        }

        private void button_TAOTUDIEN_Click(object sender, EventArgs e)
        {
            form_TAOTUDIEN form_TTD = new form_TAOTUDIEN();
            form_TTD.Show();
            form_TTD.label_TENTUDIEN_1.Hide();
            form_TTD.label_NGONNGUDICH.Show();
            form_TTD.label_NGONNGUNGUON.Show();
            form_TTD.button_TAOTUDIEN.Show();
            form_TTD.button_SUATUDIEN.Hide();
            form_TTD.combobox_TENTUDIEN_1.Hide();
            form_TTD.button_XOATUDIEN.Hide();
            form_TTD.Text = "Tạo Từ Điển";
        }

        private void button_SUATUDIEN_Click(object sender, EventArgs e)
        {
            form_TAOTUDIEN form_TTD = new form_TAOTUDIEN();
            form_TTD.Show();
            form_TTD.label_TENTUDIEN_1.Show();
            form_TTD.label_NGONNGUDICH.Show();
            form_TTD.label_NGONNGUNGUON.Show();
            form_TTD.button_TAOTUDIEN.Hide();
            form_TTD.button_SUATUDIEN.Show();
            form_TTD.button_SUATUDIEN.Top = form_TTD.button_TAOTUDIEN.Top;
            form_TTD.button_SUATUDIEN.Left = form_TTD.button_TAOTUDIEN.Left;
            form_TTD.combobox_TENTUDIEN_1.Show();
            form_TTD.button_XOATUDIEN.Hide();
            form_TTD.Text = "Sửa Từ Điển";
        }

        private void button_XOATUDIEN_Click(object sender, EventArgs e)
        {
            form_TAOTUDIEN form_TTD = new form_TAOTUDIEN();
            form_TTD.Show();
            form_TTD.label_TENTUDIEN_1.Show();
            form_TTD.combobox_TENTUDIEN_1.Show();
            form_TTD.label_NGONNGUNGUON.Hide();
            form_TTD.label_NGONNGUDICH.Hide();
            form_TTD.textbox_NGONNGUDICH.Hide();
            form_TTD.textbox_NGONNGUNGUON.Hide();
            form_TTD.button_TAOTUDIEN.Hide();
            form_TTD.button_SUATUDIEN.Hide();
            form_TTD.button_XOATUDIEN.Show();
            form_TTD.Text = "Xóa Từ Điển";
        }

        private void button_THEMTU_Click(object sender, EventArgs e)
        {
            form_THEMTU form_TT = new form_THEMTU();
            form_TT.Show();
            form_TT.combobox_TU.Hide();
            form_TT.button_SUATU.Hide();
            form_TT.button_XOATU.Hide();
        }

        private void button_SUATU_Click(object sender, EventArgs e)
        {
            form_THEMTU form_TT = new form_THEMTU();
            form_TT.Show();
            form_TT.texbox_TU.Hide();
            form_TT.combobox_TU.Show();
            form_TT.combobox_TU.Top = form_TT.texbox_TU.Top;
            form_TT.combobox_TU.Left = form_TT.texbox_TU.Left;
            form_TT.Text = "Sửa Từ";
            form_TT.button_SUATU.Show();
            form_TT.button_THEMTU.Hide();
            form_TT.button_XOATU.Hide();
        }

        private void button_XOATU_Click(object sender, EventArgs e)
        {
            form_THEMTU form_TT = new form_THEMTU();
            form_TT.Show();
            form_TT.texbox_TU.Hide();
            form_TT.combobox_TU.Show();
            form_TT.combobox_TU.Top = form_TT.texbox_TU.Top;
            form_TT.combobox_TU.Left = form_TT.texbox_TU.Left;
            form_TT.textbox_NGHIA.Hide();
            form_TT.textbox_PHIENAM.Hide();
            form_TT.textbox_TULOAI.Hide();
            form_TT.label_NGHIA.Hide();
            form_TT.label_PHIENAM.Hide();
            form_TT.label_TULOAI.Hide();
            form_TT.Text = "Xóa Từ";
            form_TT.button_SUATU.Hide();
            form_TT.button_THEMTU.Hide();
            form_TT.button_XOATU.Show();
        }

        private void frm_TTD_Load(object sender, EventArgs e)
        {

        }

        private void frm_GT_Load(object sender, EventArgs e)
        {

        }

        private void frm_TT_Load(object sender, EventArgs e)
        {

        }

        private void listbox_DANHSACHTU_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ReadCom = "select * from Tu where Tu.Tu='" + listbox_DANHSACHTU.SelectedItem.ToString() + "'";
            richtextbox_NOIDUNG.Text=listbox_DANHSACHTU.SelectedItem.ToString();
            OleDbCommand Command = new OleDbCommand(ReadCom, csdl.connectSYSTEM);
            string str = "";
            OleDbDataReader Reader;
            Reader = Command.ExecuteReader();
            Reader.Read();
            richtextbox_NOIDUNG.Text += '\n';
            richtextbox_NOIDUNG.Text += Reader.GetString(1);
            richtextbox_NOIDUNG.Text += '\n';
            richtextbox_NOIDUNG.Text += Reader.GetString(2);
            richtextbox_NOIDUNG.Text += '\n';
            richtextbox_NOIDUNG.Text += Reader.GetString(3);
        }
    }
}
